﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Chizx.Web.summary
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
        {
            if (null == Session["UserEntity"])
            {
                Response.Redirect("/e/Login.aspx");
            }
            //实习总结发布页面仅实习生可以访问
            if (Session["UserDegree"].ToString() == "SX")
            {
                Chizx.Model.UserModel umodel = (Chizx.Model.UserModel)Session["UserEntity"];
                Chizx.Model.ApplyModel am = new Chizx.Model.ApplyModel();
                Chizx.BLL.ApplyBll ab = new Chizx.BLL.ApplyBll();
                Chizx.Model.SummaryModel sm = new Chizx.Model.SummaryModel();
                Chizx.Model.CompanysModel cm = new Chizx.Model.CompanysModel();
                Chizx.BLL.CompanysBll cb = new Chizx.BLL.CompanysBll();
                am = ab.GetModelByUID(umodel.zu_id);
                if (am.za_cid == 0)
                {//自主实习
                    txtzsm_type.Text = "自主实习";
                    txtzsm_cid.Text = "无";
                    txtzsm_applydesc.Text = "无(或见申请详情)";
                }
                else
                {//分配实习
                    txtzsm_type.Text = "分配实习";
                    txtzsm_cid.Text = am.za_cid.ToString();
                    int zc_id = int.Parse(am.za_cid.ToString());
                    cm = cb.GetModel(zc_id);
                    txtzsm_applydesc.Text = cm.zcom_desc;
                }
                txtzsm_cid.Enabled = false;
                txtzsm_applydesc.Enabled = false;
                txtzsm_type.Enabled = false;
                txtzsm_cname.Text = am.za_cname;
                txtzsm_cname.Enabled = false;
                txtzsm_caddress.Text = am.za_caddress;
                txtzsm_caddress.Enabled = false;
                txtzsm_applydesc.Text = am.za_desc;
                txtzsm_applydesc.Enabled = false;
            }
			if (!Page.IsPostBack)
			{
				int zsm_id = -1;
				if (Request.Params["id0"] != null && Request.Params["id0"].Trim() != "")
				{
					zsm_id=(Convert.ToInt32(Request.Params["id0"]));
				}
				string zu_id = "";
				if (Request.Params["id1"] != null && Request.Params["id1"].Trim() != "")
				{
					zu_id= Request.Params["id1"];
				}
				ShowInfo(zsm_id,zu_id);
			}
		}
			
	private void ShowInfo(int zsm_id,string zu_id)
	{
		Chizx.BLL.SummaryBll bll=new Chizx.BLL.SummaryBll();
		Chizx.Model.SummaryModel model=bll.GetModel(zsm_id,zu_id);
		this.lblzsm_id.Text=model.zsm_id.ToString();
		this.lblzu_id.Text=model.zu_id;
        this.txtzsm_type.Text = model.zsm_type == "s0" ? "自主实习" : (model.zsm_type == "s1" ? "分配实习" : "未知");
        this.txtzsm_cid.Text = model.zsm_cid == 0 ? "无" : model.zsm_cid.ToString();
		this.txtzsm_cname.Text=model.zsm_cname;
		this.txtzsm_caddress.Text=model.zsm_caddress;
		this.txtzsm_applydesc.Text=model.zsm_applydesc;
		this.txtzsm_journalnum.Text=model.zsm_journalnum.ToString();
		this.txtzsm_context.Text=model.zsm_context;
		this.txtzsm_attachpath.Text=model.zsm_attachpath;
		this.txtzsm_check.Text=model.zsm_check;
		this.txtzsm_createdate.Text=model.zsm_createdate.ToString();
        this.txtzsm_status.Text = model.zsm_status == "s0" ? "未审核" : (model.zsm_status == "s1" ? "审核通过,已结束" : (model.zsm_status == "s2" ? "审核未通过,已驳回" : "未知状态"));

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtzsm_type.Text.Trim().Length==0)
			{
				strErr+="zsm_type不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtzsm_cid.Text))
			{
				strErr+="zsm_cid格式错误！\\n";	
			}
			if(this.txtzsm_cname.Text.Trim().Length==0)
			{
				strErr+="zsm_cname不能为空！\\n";	
			}
			if(this.txtzsm_caddress.Text.Trim().Length==0)
			{
				strErr+="zsm_caddress不能为空！\\n";	
			}
			if(this.txtzsm_applydesc.Text.Trim().Length==0)
			{
				strErr+="zsm_applydesc不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtzsm_journalnum.Text))
			{
				strErr+="zsm_journalnum格式错误！\\n";	
			}
			if(this.txtzsm_context.Text.Trim().Length==0)
			{
				strErr+="zsm_context不能为空！\\n";	
			}
			if(this.txtzsm_attachpath.Text.Trim().Length==0)
			{
				strErr+="zsm_attachpath不能为空！\\n";	
			}
			if(this.txtzsm_check.Text.Trim().Length==0)
			{
				strErr+="zsm_check不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtzsm_createdate.Text))
			{
				strErr+="zsm_createdate格式错误！\\n";	
			}
			if(this.txtzsm_status.Text.Trim().Length==0)
			{
				strErr+="zsm_status不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int zsm_id=int.Parse(this.lblzsm_id.Text);
			string zu_id=this.lblzu_id.Text;
            string zsm_type = this.txtzsm_type.Text == "自主实习" ? "s0" : (this.txtzsm_type.Text == "分配实习" ? "s1" : "s2");
			int zsm_cid=int.Parse(this.txtzsm_cid.Text);
			string zsm_cname=this.txtzsm_cname.Text;
			string zsm_caddress=this.txtzsm_caddress.Text;
			string zsm_applydesc=this.txtzsm_applydesc.Text;
			int zsm_journalnum=int.Parse(this.txtzsm_journalnum.Text);
			string zsm_context=this.txtzsm_context.Text;
			string zsm_attachpath=this.txtzsm_attachpath.Text;
			string zsm_check=this.txtzsm_check.Text;
			DateTime zsm_createdate=DateTime.Parse(this.txtzsm_createdate.Text);
            string zsm_status = this.txtzsm_status.Text == "未结束" ? "s0" : (this.txtzsm_status.Text == "已结束" ? "s1" : "s2");


			Chizx.Model.SummaryModel model=new Chizx.Model.SummaryModel();
			model.zsm_id=zsm_id;
			model.zu_id=zu_id;
			model.zsm_type=zsm_type;
			model.zsm_cid=zsm_cid;
			model.zsm_cname=zsm_cname;
			model.zsm_caddress=zsm_caddress;
			model.zsm_applydesc=zsm_applydesc;
			model.zsm_journalnum=zsm_journalnum;
			model.zsm_context=zsm_context;
			model.zsm_attachpath=zsm_attachpath;
			model.zsm_check=zsm_check;
			model.zsm_createdate=zsm_createdate;
			model.zsm_status=zsm_status;
            //写入系统日志
            if (Session["UserEntity"] == null)
            {
                Response.Redirect("/e/Login.aspx");
            }
            else
            {
                Chizx.BLL.SummaryBll bll = new Chizx.BLL.SummaryBll();
                bll.Update(model);
                Chizx.Model.UserModel sbmmodel = (Chizx.Model.UserModel)Session["UserEntity"];
                Chizx.BLL.SystemLogBll sbll = new Chizx.BLL.SystemLogBll();
                Chizx.Model.SystemLogModel slm = new Chizx.Model.SystemLogModel();
                slm.zu_id = sbmmodel.zu_id;
                slm.zl_dowhen = DateTime.Now;
                slm.zl_dowhat = "修改实习总结";
                slm.zl_dotype = "3";//0:Test,1:Auth,2:Read,3:Write,4:Del,5:Inpor
                slm.zl_dodesc = "操作成功";
                sbll.Add(slm);
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");
            }
		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
